﻿using System;
using System.Collections.Generic;
using System.Web;
using PayRoller.Code;
using System.Web.SessionState;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using HySoft.Cash.Business;
using HySoft.Cash.Structure;
using System.Configuration;
using System.Web.Profile;

namespace PayRoller.Manage.OrgInfo
{
    public class EditCredit : ParentPage, IRequiresSessionState
    {
        // Fields
        protected Button bnSave;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        protected Label lblTip;
        public string OrgSid = "";
        protected TextBox txtCreditLimit;
        protected TextBox txtExpCreditLimit;

        // Methods
        protected void bnSave_Click(object sender, EventArgs e)
        {
            TorginfoBN obn = new TorginfoBN(this.Page);
            TorginfoDT detail = obn.Get(Convert.ToInt32(this.OrgSid));
            detail.Sid = Convert.ToInt32(this.OrgSid);
            detail.CreditLimit = Convert.ToDecimal(this.txtCreditLimit.Text);
            obn.Edit(detail);
            obn.Dispose();
            obn = null;
            base.ClientScript.RegisterStartupScript(base.GetType(), "", "<script>alert('Success!');window.location='Index.aspx?OrgSid=" + this.OrgSid + "';</script>");
        }

        protected override void OnInit(EventArgs e)
        {
            base.m_ModuleCode = "0005";
            base.CheckLogin(true);
            base.CheckPerm();
            base.OnInit(e);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (base.Request["OrgSid"] != null)
            {
                this.OrgSid = base.Request["OrgSid"].ToString();
                if (!this.Page.IsPostBack)
                {
                    try
                    {
                        TorginfoBN obn = new TorginfoBN(this.Page);
                        TorginfoDT odt = obn.Get(Convert.ToInt32(this.OrgSid));
                        this.txtExpCreditLimit.Text = odt.ExpCreditLimit.ToString();
                        this.txtCreditLimit.Text = odt.CreditLimit.ToString();
                        obn.Dispose();
                        obn = null;
                    }
                    catch (Exception exception)
                    {
                        this.lblTip.Text = exception.Message;
                    }
                }
            }
        }

        // Properties
        protected HttpApplication ApplicationInstance
        {
            get
            {
                return this.Context.ApplicationInstance;
            }
        }

        protected DefaultProfile Profile
        {
            get
            {
                return (DefaultProfile)this.Context.Profile;
            }
        }
    }

}
